﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
using System.IO;

namespace ft_module_parser
{
    static class rescb
    {
        public static bool state = false;
        public static byte[] spr_sel_pv;
        public static void InitResc()
        {
            if (!state)
            {
                //Console.Write("Initializing...");

                //spr_sel_pv = Brotli.DecompressBuffer(Properties.Resources.spr_sel_pv, 0, Properties.Resources.spr_sel_pv.Length /**, customDictionary **/);
                ZipArchive zip = new ZipArchive(new MemoryStream(Properties.Resources.spr_sel_pv));
                spr_sel_pv = ReadFully(zip.Entries.First().Open());

                //Console.CursorLeft = 0;
                //Console.Write("                      ");
                //Console.CursorLeft = 0;
                state = true;
            }
            GC.Collect();
        }

        public static byte[] ReadFully(Stream input)
        {
            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }
    }
}
